<?php
//error_reporting(E_ERROR);
require_once 'class/phpqrcode/phpqrcode.php';

$data = isset($_GET["data"]) ? urldecode($_GET['data']) : ''; //二维码内容
if (!$data) exit;
$logo = isset($_GET["logo"]) ? $_SERVER['DOCUMENT_ROOT'].urldecode($_GET['logo']) : ''; //logo图片
$errorCorrectionLevel = 'L'; //容错级别
$matrixPointSize = 6; //生成图片大小
$QR = $_SERVER['DOCUMENT_ROOT'].'/uploadfiles/qrcode.png';//已生成的二维码图片文件名

if (!$logo) { 
	QRcode::png($data, false, $errorCorrectionLevel, $matrixPointSize, 0);
} else {
	QRcode::png($data, $QR, $errorCorrectionLevel, $matrixPointSize, 0);
	$QR = imagecreatefromstring(file_get_contents($QR));
	$logo = imagecreatefromstring(file_get_contents($logo));
	$QR_width = imagesx($QR); //二维码宽度
	$QR_height = imagesy($QR); //二维码高度
	$logo_width = imagesx($logo); //logo宽度
	$logo_height = imagesy($logo); //logo高度
	$logo_qr_width = $QR_width / 2.5;
	$scale = $logo_width / $logo_qr_width;
	$logo_qr_height = $logo_height / $scale;
	$from_width = ($QR_width - $logo_qr_width) / 2;
	//重新组合图片并调整大小
	imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
	header("Content-type: image/png");
	imagepng($QR);
}